package com.training.java.core.collections.car.post15;

/**
 * This is an example to demonstrate how the collections work. Objective:Create
 * multiple fruits objects and adding to the collection.
 * 
 * @author Satya
 * 
 */

public class Fruit implements Comparable<Fruit> {

	// State of the object fruit
	private String name;
	private String color;
	private String taste;
	private int price;// give the setter method to change the value later

	// Creating the constructor to initiate values for instance variables

	public Fruit(String name, String color, String taste, int price)

	{
		this.name = name;
		this.color = color;
		this.taste = taste;
		this.price = price;
	}

	// Create Getters to get the info of instance variable.

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the color
	 */
	public String getColor() {
		return color;
	}

	/**
	 * @return the taste
	 */
	public String getTaste() {
		return taste;
	}

	/**
	 * @return the price
	 */
	public int getPrice() {
		return price;
	}

	// Setter methods.

	/**
	 * @param to
	 *            set the price
	 */
	public void setPrice(int price) {
		this.price = price;
	}

	@Override
	public boolean equals(Object obj) {

		// Instanceof-- checking the parameter is real time object Fruit or not.
		// If it is not real Fruit object, it should
		// return False.

		if (obj instanceof Fruit)

		{
			Fruit fruit1 = (Fruit) obj; // Casting
			return this.name.equals(fruit1.name)
					&& this.color.equals(fruit1.color);

		} else {
			return false;

		}

	}// end of equals method

	// Overriding the hashCode

	@Override
	public int hashCode() {
		return name.hashCode() + color.hashCode() + taste.hashCode();
	}

	/**
	 * compareTo method for TreesetDemo
	 * 
	 */

	@Override
	public int compareTo(Fruit that) {

		return this.name.compareTo(that.name);
	}

}
